package com.juyu.miliao.api.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.juyu.miliao.api.domain.Vip;
import com.juyu.miliao.api.service.VipService;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.util.AppPackageIdUtil;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/vip")
public class VipController {

    @Resource
    private VipService vipService;

    /**
     * 获取vip信息
     *
     * @return
     */
    @GetMapping()
    public List<Vip> getVipList(HttpServletRequest request) {
        //应用Id,用来区分马甲包与线上包
        String appPackageId = AppPackageIdUtil.null2AppPackageId(request);
        return vipService.getVipList(appPackageId);
    }

    /**
     * 获取vip支付弹窗信息，马甲包专用
     *
     * @param request
     * @return
     */
    @GetMapping("/payVip")
    public List<Vip> getPayVipList(HttpServletRequest request) {
        //应用Id,用来区分马甲包与线上包
        String appPackageId = AppPackageIdUtil.null2AppPackageId(request);
        return vipService.getPayVipList(appPackageId);
    }

    /**
     * 获取vip applePay
     *
     * @param type
     * @return
     */
    @GetMapping("/{type}")
    public List<Vip> getVipListByType(@PathVariable("type") Integer type) {
        return vipService.getVipListByType(type);
    }

    @GetMapping("/list/{type}")
    public Object getNewVipListByType(Authentication token, @PathVariable("type") Integer type){
        Subject subject = (Subject) token.getPrincipal();
        return vipService.getNewVipListByType(subject.getId(),type);
    }
}
